package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppArea;
import com.ruoyi.app.service.IAppAreaService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地区Controller
 *
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/app/area")
public class AppAreaController extends BaseController
{
    @Autowired
    private IAppAreaService appAreaService;

    /**
     * 查询地区列表
     */
    @PreAuthorize("@ss.hasPermi('app:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppArea appArea)
    {
        startPage();
        List<AppArea> list = appAreaService.selectAppAreaList(appArea);
        return getDataTable(list);
    }

    /**
     * 导出地区列表
     */
    @PreAuthorize("@ss.hasPermi('app:area:export')")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppArea appArea)
    {
        List<AppArea> list = appAreaService.selectAppAreaList(appArea);
        ExcelUtil<AppArea> util = new ExcelUtil<AppArea>(AppArea.class);
        util.exportExcel(response, list, "地区数据");
    }

    /**
     * 获取地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(appAreaService.selectAppAreaByAreaId(areaId));
    }

    /**
     * 新增地区
     */
    @PreAuthorize("@ss.hasPermi('app:area:add')")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppArea appArea)
    {
        return toAjax(appAreaService.insertAppArea(appArea));
    }

    /**
     * 修改地区
     */
    @PreAuthorize("@ss.hasPermi('app:area:edit')")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppArea appArea)
    {
        return toAjax(appAreaService.updateAppArea(appArea));
    }

    /**
     * 删除地区
     */
    @PreAuthorize("@ss.hasPermi('app:area:remove')")
    @Log(title = "地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(appAreaService.deleteAppAreaByAreaIds(areaIds));
    }
}
